//
//  XGPictureTopicTableViewCell.m
//  BSBuDeJie
//
//  Created by monkey on 2018/12/30.
//  Copyright © 2018 itcast. All rights reserved.
//

#import <Masonry/Masonry.h>

#import "UIImageView+Extension.h"

#import "XGPictureTopicTableViewCell.h"
#import "XGTopicCellTopCommentView.h"
#import "XGPictureTopicView.h"

#import "XGTopicModel.h"

@interface XGPictureTopicTableViewCell ()

/// 图片视图
@property (nonatomic,strong) XGPictureTopicView *pictureView;

@end

@implementation XGPictureTopicTableViewCell

- (void)setUpUI
{
    [super setUpUI];
    
    // 添加子控件
    [self.contentView addSubview:self.pictureView];
    
    // 自动布局
    [self.pictureView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentLabel.mas_bottom).offset(kMargin);
        make.left.right.equalTo(self.contentLabel);
        make.height.mas_equalTo(100);   // 随意指定 动态计算
    }];
    
    [self.topCommentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.pictureView.mas_bottom).offset(kMargin);
    }];
}

- (void)setTopicModel:(XGTopicModel *)topicModel
{
    [super setTopicModel:topicModel];
    
    // 设置图片视图数据
    self.pictureView.topicModel = topicModel;
    
    // 动态计算图片高度
    CGFloat height = (SCREEN_WIDTH - 2 * kMargin) / topicModel.width * topicModel.height;
    height = height > (SCREEN_HEIGHT * 0.8) ? kDefaultPictureHeight : height;
    [self.pictureView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(height);
    }];
}

#pragma mark - 懒加载

- (XGPictureTopicView *)pictureView
{
    if (_pictureView == nil) {
        _pictureView = [[XGPictureTopicView alloc] init];
    }
    
    return _pictureView;
}


@end
